﻿using System.Threading;
using EzDesk.DesktopClient.FunctionWindowModule.ViewContract;
using EzDesk.DesktopClient.FunctionWindowModule.ViewModel;
using EzDesk.Utility.Net;
using Moq;
using NUnit.Framework;

namespace EzDesk.DesktopClient.UnitTest.FunctionWindowModule_Fixture
{
    [TestFixture]
    public class ActionViewModel_Fixture
    {
        [Test]
        public void doaction()
        {
            //Arrange
            var mockUrl = "http://www.g.cn?target=action";
            var mockReturnValue = "{State:'Success',Info:'您已经确定了改变世界的消息！',Data:null}";
            var m_WebRequest = new Mock<IWebRequestExt>();
            var m_ActionView = new Mock<IActionView>();
            var m_DataManagment = new Mock<IDataManagement>();

            m_WebRequest
                .Setup(wr => wr.GetStringFromUrl(It.IsAny<string>()))
                .Returns(mockReturnValue);
            

            //Action
            var actionViewModel = new ActionViewModel(m_WebRequest.Object,m_DataManagment.Object);
            actionViewModel.View = m_ActionView.Object;
            actionViewModel.DoAction(mockUrl);

            //Assert
            m_WebRequest.Verify(wr => wr.GetStringFromUrl(mockUrl), Times.AtLeastOnce());
            m_ActionView.Verify(av => av.FlashShow(), Times.AtLeastOnce());
            Thread.Sleep(3000);
            m_DataManagment.Verify(dm=>dm.RefreshDataFromServer(),Times.AtLeastOnce());

            Assert.AreEqual("操作成功！", actionViewModel.IsSuccess);
            Assert.AreEqual("您已经确定了改变世界的消息！", actionViewModel.ResultInformation);

        }


    }
}
